const Router = require("@koa/router");
const { auth, hadAdminPermission } = require("../middleware/authMiddleware");
const {
  upload,
  create,
  update,
  remove,
  restore,
  findAll,
  search
} = require("../controller/goodsController");
const { validator } = require("../middleware/goodsMiddleware");
const router = new Router({ prefix: "/goods" });
// 1、商品文件上传
router.post("/upload", auth, hadAdminPermission, upload);
// 2、发布商品
router.post("/", auth, hadAdminPermission, validator, create);
// 3、修改商品
router.put("/:id", auth, hadAdminPermission, validator, update);
// 4、删除商品
router.delete("/:id", auth, hadAdminPermission, remove);
// 5、商品下架
router.post("/:id/off", auth, hadAdminPermission, remove);
// 6、商品上架
router.post("/:id/on", auth, hadAdminPermission, restore);
// 7、商品列表
router.get("/", findAll);
// 8、搜索商品
router.get("/search", auth, search)
module.exports = router;
